//config
Config = function (x){
    this.server = x.server;
    this.location = x.location;
};
Config.prototype = {
    server : null,
    location : {
            id : null,
            nama : null
    },
    getDate : function(){
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth()+1;
            var d = date.getDate();
            if (m<10) {
                    m = "0"+m;
            }
            if (d<10) {
                    d = "0"+d;
            }
            return y+"-"+m+"-"+d;
    },
    startUp : function(){
        layout.frame.inject();
        layout.frame.hide();
        frame.startUp.inject();
        frame.startUp.load();
        frame.kuitansiTransaksi.inject();
        frame.kuitansiTransaksi.load();
        /*
        layout.windows.hide();
        layout.login.show();
        */
    }
};
//option
option = new Object();
option.DataSource = function(x){
    var TransportOption = function (url,data){
        this.url = url;
        this.type = "POST";
        this.data = data;
    };
    if (x.url){
        if (x.dataC){
            this.transport.create = new TransportOption(x.url,x.dataC);
        };
        if (x.dataR){
            this.transport.read = new TransportOption(x.url,x.dataR);  
        };
        if (x.dataU){
            this.transport.update = new TransportOption(x.url,x.dataU);
        };
        if (x.dataD){
            this.transport.destroy = new TransportOption(x.url,x.dataD);  
        };
    };
    this.schema = x.schema;
};
option.DataSource.prototype = {
    transport : {},
    pageSize : 10,
    error : function(e){alert("error");},
    schema : {
    }
};
option.DropDown = function(x){
    this.dataSource = x.dataSource;
    if(x.dataBound){
        this.dataBound = x.dataBound;
    };
    if(x.change){
        this.change = x.change;
    };
};
option.DropDown.prototype = {
    dataTextField : "text",
    dataValueField : "value",
    dataSource : null,
    optionLabel : "-"
};
option.Grid = function(x){
    this.dataSource = x.dataSource;
    this.columns = x.columns;
};
option.Grid.prototype = {
    editable : "popup",
    filterable : { extra : false },
    columnMenu : true,
    resizeable : true,
    pageable : true,
    dataSource : {},
    columns : {}
};
//fk
Fk = function(x){
    this.load = x.load;
};
Fk.protype = {
    data : null,
    load : function(){}
}
//dbModel (id,url,{data(CRUD)})
DbModel = function(x){
    var opt = new option.DataSource(x);
    this.source = new kendo.data.DataSource(opt);
    this.getNewId = x.getNewId;
};
DbModel.prototype = {
    source : null,
    refresh : function(){},
    getNewId : function(){}
};
//layout
Layout = function(x){
    this.placeholder = x.placeholder;
    this.inject = function(){
        this.show = function(){
            $(this.placeholder).show();
        };
        this.hide = function(){
            $(this.placeholder).hide();
        };
        if (this.tipe === "menu"){
            var menu = "";
            $.each(x.items, function(i,n){
                menu = menu + "<li id='" + n.id + "' onClick=menu." + x.id + ".option.items["+i+"].fungsi()>" + n.text + "</li>";
            });
            $(this.placeholder).html(menu);
            $(this.placeholder).kendoMenu();
        };
        if (this.tipe === "grid"){
            var opt = new option.Grid(x);
            this.grid = $(x.placeholder).kendoGrid(opt);
        }
    };
};
Layout.prototype = {
    placeholder : null,
    tipe : "layout",
    show : function(){},
    hide : function(){},
    inject : function(){}
};
//Log
Log = function(x){
    Layout.call(this,x);
};
Log.prototype = {
    notification : {
        tipe : "log",
        text : null,
        time : null
    },
    set : function(x){
        this.notification.text = x.text;
        var stat = this.notification.time = x.time;
        var dur = stat*1000;
        $(this.placeholder).hide();
        $(this.placeholder).html(null);
        $(this.placeholder).html(this.notification.text);
        if (stat===0){
            $(this.placeholder).show(100)
        }
        else {
            $(this.placeholder).show(100).delay(dur).hide(100)
        };
        
    }
};
//Menu
Menu = function(x){
    Layout.call(this,x);
    this.option = x;
};
Menu.prototype = {
    tipe : "menu",
    option : {
        items : [
            {
                
            }
        ]
    }
};
//frame
Frame = function (x){
    Layout.call(this,x);
    this.file = x.file;
    this.load = function(){
        $.ajax({
            url: this.file,
            cache: false,
            dataType: "html",
            success: x.success
        });
    };
};
Frame.prototype = {
    tipe : "frame",
    file : null,
    success : null,
    load : function() {}
};
//formz
Formz = function (x){
    Frame.call(this,x);
    this.resetValues = x.resetValues;
    this.simpan = x.simpan;
};
Formz.prototype = {
    tipe : "form",
    resetValues : function(){},
    simpan : function(){}
};
//grid (column,placeholder)
Grid = function(x){
    Layout.call(this,x);
};
Grid.prototype = {
    tipe : "grid",
    grid : null
};